home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1993 October / Simtel 20 Collection (Walnut Creek CD-ROM)(October 1993).ISO / _bbs / rbbstool / makemenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-12  |  2.4 KB  |  123 lines

  1. /*
  2.  * read \_bbs\dirs.txt and parameter (batch file) 
  3.  * for each line in there.
  4.  */
  5.  
  6. #include <ctype.h>
  7. #include <stdarg.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <stdio.h>
  11.  
  12.  
  13.  
  14. void
  15. help(void) {
  16.  
  17.     fprintf(stderr,
  18.               "makemenu: build core of menu based on dirs.txt\n");
  19.     fprintf(stderr,
  20.         "usage: makemenu <starting area #> <dirs.txt path> -xxx> <out file>\n");
  21.     fprintf(stderr, "-xxx == -n for normal, -a for ansi, -g for graphics.\n");
  22.     exit(1);
  23. }
  24.  
  25. void _Cdecl
  26. main(int argc, char *argv[]) {
  27.     char buf[200];
  28.     char output[200];
  29.     char batchfile[80];
  30.     char *p;
  31.     int count;
  32.     FILE *dirsfile;
  33.     int i;
  34.     int do_normal = 0;
  35.     int do_ansi = 0;
  36.     int do_graphic = 0;
  37.     
  38.     fprintf(stderr,
  39.           "Makemenu.  Walnut Creek CDROM, copyright 1993.\n");
  40.  
  41.     if (argc < 4)
  42.         help();
  43.  
  44.     if (0 == (count = atoi(argv[1])))
  45.         help();
  46.  
  47.      if (NULL == (dirsfile = fopen(argv[2], "r"))) {
  48.         fprintf(stderr, "failed opening directory listing '%s'\n   %s\n",
  49.                   argv[2]);
  50.         help();
  51.     }
  52.  
  53.     if (0 == strcmp(strlwr(argv[3]), "-n"))
  54.         ++do_normal;
  55.     else if (0 == strcmp(strlwr(argv[3]), "-a"))
  56.         ++do_ansi;
  57.     else if (0 == strcmp(strlwr(argv[3]), "-g"))
  58.         ++do_graphic;
  59.     else
  60.         help();
  61.  
  62.     
  63.     while (NULL != fgets(buf, 199, dirsfile)) {
  64.  
  65.         /* wack off trailing spaces */
  66.         i = strlen(buf) - 1;
  67.         while (i >= 0 && isspace(buf[i])) {
  68.             buf[i] = '\0';
  69.             --i;
  70.         }
  71.         
  72.         p = strchr(buf, ' ');
  73.         if (!p) {
  74.             fprintf(stderr, "something wrong with line `%s'\n", buf);
  75.             help();
  76.         }
  77.         while (isspace(*p))
  78.                  ++p;
  79.  
  80.         sprintf(output, "%3d %-32s", count++, p);
  81.         
  82.         if (NULL == fgets(buf, 199, dirsfile)) {
  83.             if (do_ansi)
  84.                 printf("│");
  85.             if (do_graphic)
  86.                 printf("│");
  87.             printf("%s %3s %32s", output, " ", " ");
  88.             if (do_ansi)
  89.                 printf("│");
  90.             if (do_graphic)
  91.                 printf("│");
  92.             printf("\n");
  93.             exit(0);
  94.         }
  95.         
  96.         /* wack off trailing spaces */
  97.         i = strlen(buf) - 1;
  98.         while (i >= 0 && isspace(buf[i])) {
  99.             buf[i] = '\0';
  100.             --i;
  101.         }
  102.         
  103.         p = strchr(buf, ' ');
  104.         if (!p) {
  105.             fprintf(stderr, "something wrong with line `%s'\n", buf);
  106.             help();
  107.         }
  108.         while (isspace(*p))
  109.                  ++p;
  110.         
  111.         if (do_ansi)
  112.             printf("│");
  113.         if (do_graphic)
  114.                 printf("│");
  115.         printf("%s %3d %-32s", output, count++, p);
  116.         if (do_ansi)
  117.             printf("│");
  118.         if (do_graphic)
  119.                 printf("│");
  120.         printf("\n");
  121.     }
  122. }
  123.